package com.sdp.wz.db.wz_warehouse_info.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sdp.wz.db.wz_warehouse_info.entity.WzWarehouseInfo;
import com.sdp.wz.db.wz_warehouse_info.mapper.WzWarehouseInfoMapper;
import com.sdp.wz.db.wz_warehouse_info.service.IWzWarehouseInfoService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zsp
 * @since 2024-07-29
 */
@Service
public class WzWarehouseInfoServiceImpl extends ServiceImpl<WzWarehouseInfoMapper, WzWarehouseInfo> implements IWzWarehouseInfoService {

	@Override
	public WzWarehouseInfo queryWarehouseInfoByCode(String warehouseCode) {
		LambdaQueryWrapper<WzWarehouseInfo> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(WzWarehouseInfo::getWarehouseCode, warehouseCode);
		return getOne(queryWrapper,false);
	}

	
	@Override
	public List<JSONObject> queryWzWarehouseTreeSelect() {
		List<JSONObject> treeList = new ArrayList<JSONObject>();
		LambdaQueryWrapper<WzWarehouseInfo> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.orderByAsc(WzWarehouseInfo::getOrgNo);
		queryWrapper.orderByAsc(WzWarehouseInfo::getWarehouseCode);
		List<WzWarehouseInfo> warehouseList = list(queryWrapper);

		if(warehouseList!=null && warehouseList.size()>0) {
			
			for(int i=0;i<warehouseList.size();i++) {
				JSONObject parentObj = new JSONObject();
				parentObj.put("title", warehouseList.get(i).getWarehouseName());
				parentObj.put("value", warehouseList.get(i).getWarehouseCode());
				parentObj.put("key",warehouseList.get(i).getKeyId());
				treeList.add(parentObj);
			}
		}
		
		return treeList;
	}
	
}
